import React, { useState } from "react";
import instance from "../../api/request";
import md5 from "md5";
import { Button, Input } from "antd";
const appKey = "0c03b7d88ce36a25";
const appMiyao = "He1zJjsEUnsqf9DePmFaCjo50MN2jE2Z";
function Index() {
  const [list, setList] = useState();
  const [data, setData] = useState();
  const fy = async () => {
    const salt=Date.now().toString()
    const sign=md5(appKey+data+salt+appMiyao)
    const params = {
      q: data,
      from: 'auto',
      to: 'auto',
      appKey: appKey,
      salt,
      sign,
    };
    const res=await instance.get('/youdao/api',{params})
    console.log(res);
    setList(res.data.translation[0])
    
  };
  return <div>
    <Input onChange={(e)=>setData(e.target.value)}></Input>
    <Button onClick={fy}>翻译</Button>
    <div>
      {list}
    </div>
  </div>;
}

export default Index;
